cmake_minimum_required(VERSION 3.10)

project(Modbus_Serial_Port)

# 1. 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 2. 静态库输出到lib目录下
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) #  将编译后的可执行程序输出到bin目录下

# 3. 添加各模块的子目录
add_subdirectory(src/tools)
add_subdirectory(src/serial_port)
add_subdirectory(src/modbus_serial_port)

# 4. 合并所有模块源码，生成静态库 `modbus_serial`
add_library(modbus_serial STATICS
    ${TOOLS_SRC}
    ${SERIAL_PORT_SRC}
    ${MODBUS_SERIAL_PORT_SRC}
)

# 5. 包含头文件目录（让库和可执行文件能找到头文件）
target_include_directories(modbus_serial PUBLIC
    ${PROJECT_SOURCE_DIR}/include
)

# 6. 编译主站、从站可执行文件
add_executable(modbus_master src/test/master_test.cc)
target_link_libraries(modbus_master modbus_serial)

add_executable(modbus_slave src/test/slave_test.cc)
target_link_libraries(modbus_slave modbus_serial)

















cmake_minimum_required(VERSION 3.10)

project(ModbusSerialTest1)

# 设置交叉编译工具链
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# 指定aarch64交叉编译器
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置构建类型
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

# 设置输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 包含头文件目录
include_directories(
    ${PROJECT_SOURCE_DIR}/include
)

# 查找所有源文件
file(GLOB TOOLS_SRC "src/tools/*.cc")
file(GLOB SERIAL_PORT_SRC "src/serial_port/*.cc") 
file(GLOB MODBUS_SERIAL_PORT_SRC "src/modbus_serial_port/*.cc")

# 生成静态库
add_library(modbus_serial STATIC
    ${TOOLS_SRC}
    ${SERIAL_PORT_SRC}
    ${MODBUS_SERIAL_PORT_SRC}
)

# 编译主站、从站可执行文件
add_executable(modbus_master src/test/master_test.cc)
target_link_libraries(modbus_master modbus_serial)

add_executable(modbus_slave src/test/slave_test.cc)
target_link_libraries(modbus_slave modbus_serial)